#!/usr/bin/perl -w

#use strict;
use URI::Fetch;
use HTML::TagParser;
use LWP::UserAgent;

my $ua = LWP::UserAgent->new;
$ua->timeout(30);


open( ADDRIN, "<./in_file" );

foreach $line ( <ADDRIN> ) {

  if ( $line =~ m/^#/i ) {
    next;
  } else {
    ( $first, $last, $town ) = split( ',', $line );
    print "$first, $last, $town, NJ\n";
  }

}


sub GetAddress {
my $html = HTML::TagParser->new( 'http://anywhoyp.yellowpages.com/whitepages?from=AnyWho&fap_terms%5Bfirst%5D=\$first&fap_terms%5Blast%5D=\$last&fap_terms%5Bcity%5D=\$city&fap_terms%5Bstate%5D=\$state' );

#my $html = HTML::TagParser->new( "http://anywhoyp.yellowpages.com" );
my @list = $html->getElementsByTagName( "div" );

foreach my $elem ( @list ) {
    my $tagname = $elem->tagName;
    my $attr = $elem->attributes;
    my $text = $elem->innerText;

  #while ( (my $key, my $value) = each( %$attr ) ) {
  #  my $street = $attr->{"waypoint-b-location"};
  #      print $attr->{"waypoint-b-location"} . "\n\n";
  #key = id, value = waypoint-b-location
  #      print "key = $key, value = $value\n";
  #print "id"->{"waypoint-b-location"} . "\n\n";
  #id ==> waypoint-b-location
  #}

  #id="waypoint-b-location">
  #
  #    print "<$tagname";
  foreach my $key ( sort keys %$attr ) {
    if ( $attr->{$key} eq "waypoint-b-location" ) {
      print "$text\n";
    }
  }
  #
  #        print " Josh's Key ---->   $key=\"$attr->{$key}\"";
  #    }
  #    if ( $text eq "" ) {
  #        print " />\n";
  #    } else {
  #        print ">$text</$tagname>\n";
  #    }
}
} # End GetAddress
